package com.smasher.backup.dialog.bottomsheet;

import android.app.Dialog;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.Window;

import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

/**
 * @author HXZ_Android
 */
public abstract class BaseBottomSheetDialogFragment extends BottomSheetDialogFragment {


    public BaseBottomSheetDialogFragment() {
    }

    public BaseBottomSheetDialogFragment(int contentLayoutId) {
        super(contentLayoutId);
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE, 0);
    }

    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();

        if (dialog != null) {
            Window window = dialog.getWindow();
            if (window != null) {
                window.setLayout(getWidth(), getHeight());
            }
        }

//        if (dialog instanceof BottomSheetDialog) {
//            BottomSheetDialog bottomSheetDialog = (BottomSheetDialog) dialog;
//            BottomSheetBehavior<FrameLayout> behavior = bottomSheetDialog.getBehavior();
//            behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
//        }
    }

    /**
     * can use{@link ViewGroup.LayoutParams#MATCH_PARENT}
     * or {@link ViewGroup.LayoutParams#WRAP_CONTENT}
     * or exactly number
     */
    protected abstract int getWidth();

    /**
     * can use{@link ViewGroup.LayoutParams#MATCH_PARENT}
     * or {@link ViewGroup.LayoutParams#WRAP_CONTENT}
     * or exactly number
     */
    protected abstract int getHeight();

}
